package com.eazyshop.search.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public final static String GOODS_UP_EXCHANGE="goods_up_exchange";
    public final static String GOODS_UP_QUEUE="goods_up_queue";
    /**
     * 创建交换机
     * 类型为fanout
     * @return
     */
    @Bean(GOODS_UP_EXCHANGE)
    public Exchange exchange(){
        Exchange build = ExchangeBuilder.fanoutExchange(GOODS_UP_EXCHANGE).build();
        return build;
    }
    /**
     * 声明队列
     */

    @Bean(GOODS_UP_QUEUE)
    public Queue queue(){
        Queue build = QueueBuilder.durable((GOODS_UP_QUEUE)).build();

        return build;
    }
    /**
     * 交换机与队列绑定
     */
    @Bean
    public Binding  goodsQueueBindingExchange(@Qualifier(GOODS_UP_QUEUE) Queue queue,@Qualifier(GOODS_UP_EXCHANGE) Exchange exchange){
        Binding noargs = BindingBuilder.bind(queue).to(exchange).with("").noargs();
        return noargs;
    }

}
